package com.example.webbackend.listener;

import com.example.webbackend.model.Message;
import com.example.webbackend.service.MessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class MessageConsumer {

    private static final Logger logger = LoggerFactory.getLogger(MessageConsumer.class);
    private final MessageService messageService;

    public MessageConsumer(MessageService messageService) {
        this.messageService = messageService;
    }

    @RabbitListener(queues = "message.queue")
    public void onMessage(Message message) {
        logger.debug("[RabbitMQ] Received message from queue: {}", message);
        messageService.processAndPushMessage(message);
    }
}
